package com.sourceQ.system.controller.message.mail;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sourceQ.common.core.domain.R;
import com.sourceQ.common.core.web.controller.BaseController;
import com.sourceQ.common.core.web.domain.AjaxResult;
import com.sourceQ.common.log.annotation.Log;
import com.sourceQ.common.log.enums.BusinessType;
import com.sourceQ.system.domain.message.mail.SysMailAccount;
import com.sourceQ.system.dto.message.MailAccountPageReqDTO;
import com.sourceQ.system.dto.message.MailAccountSaveReqDTO;
import com.sourceQ.system.service.message.mail.SysMailAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author: SourceQ
 * @create: 2024-04-26 16:12
 * @Description:
 */
@RestController
@RequestMapping("/mail-account")
@Api(tags = "邮箱账号管理")
public class MailAccountController extends BaseController {
    @Autowired
    private SysMailAccountService mailAccountService;
    @ApiOperation(value = "创建邮箱账号")
    @Log(title = "邮箱账号管理",businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public AjaxResult create(@Valid @RequestBody MailAccountSaveReqDTO createReqVO){
        return toAjax(mailAccountService.createMailAccount(createReqVO)>0);
    }
    @ApiOperation(value = "修改邮箱账号")
    @Log(title = "邮箱账号管理",businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@Valid @RequestBody MailAccountSaveReqDTO updateReqVo){
        mailAccountService.updateMailAccount(updateReqVo);
        return success();
    }
    @ApiOperation(value = "删除邮箱账号")
    @Log(title = "邮箱账号管理",businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Long id){
        mailAccountService.deleteMailAccount(id);
        return success();
    }
    @ApiOperation(value = "分页查询邮箱账号")
    @Log(title = "邮箱账号管理",businessType = BusinessType.QUERY)
    @GetMapping("/page")
    public R<IPage<SysMailAccount>> page(Page page, MailAccountPageReqDTO dto){
        return R.ok(mailAccountService.getMailAccountPage(page, dto));
    }
    @ApiOperation(value = "邮箱账号详情")
    @Log(title = "邮箱账号管理",businessType = BusinessType.QUERY)
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable Long id) {
        return success(mailAccountService.getMailAccount(id));
    }
    @ApiOperation(value = "邮箱账号集合")
    @Log(title = "邮箱账号管理",businessType = BusinessType.QUERY)
    @GetMapping("/account-list")
    public AjaxResult getAccountList(){
        return success(mailAccountService.getMailAccountList());
    }

}
